%Skript finds the optimal probabilities to move forwards p and to stand
%still s, which are minimizing the maximum of the function
%'probsWithStandingStill'.

% It also have to be tested if the probability where to be after the very
% first two steps is less or equal than the minimized maximum.
% The two cases are tested: The ship can stand sill in the very first move
% or it can not stand still in the very first move. 
% It results that it has to move because otherwise the value where it will
% be after the very first two steps would be bigger than the value where it
% will be during the game. 
close all
clear

%n is the size of the n-restricted graph
global n

for n=1:10
    
   x0=rand(2,1)
   p=fminimax(@probsWithStandingStill,x0);
   % value resulting if the ship can stand still
   vStand(n)=max(probsWithStandingStill(p));
   
   % value if the ship has not the opportunity to stand still, value of the
   % original problem
   vNormal(n)=(n^2+2-n*sqrt(n*n+4))/2; 
   
   % Maximum probability where the ship will be after the very first two
   % steps if it can not stand still in the first move
   vStart(n)=max(First2StepsWithoutStandingStill(p));
   
   
   % Maximum probability where the ship will be after the very first two
   % steps if it can stand still in the first move
   vStart2(n)=max(First2StepsWithStandingStill(p));
end

figure()
subplot(3,1,1)
plot(1:n,vNormal,'p', 1:n, vStand,'p')
s=legend('v, ship can not stand still', 'v, ship can stand still');
set(s)
xlabel('n')
ylabel('v')
subplot(3,1,2)
plot( 1:n, vStand,'p', 1:n, vStart, 'p')
s=legend('v, ship can stand still', 'max v after first two steps, ship can not stant still in the first move');
set(s)
xlabel('n')
ylabel('v')
subplot(3,1,3)
plot(1:n, vStand,'p', 1:n, vStart2, 'p')
s=legend( 'v, ship can stand still', 'max v after first two steps, ship can stand still in the first move');
set(s)
xlabel('n')
ylabel('v')